<template>
  <div class="main">
    <div class="main_btn">
      <h3>层级管理</h3>
      <el-button type="primary" :icon="useRenderIcon(AddFill)" @click="HandEdit(undefined)"> 添加 </el-button>
    </div>
    <div class="main_table">
      <el-table :data="dataList" row-key="id" border max-height="750" :tree-props="{ children: 'child' }">
        <el-table-column type="index" label="序号" width="200" />
        <el-table-column prop="folderName" label="层级名称">
          <template #default="scope">
            <el-icon v-if="scope?.row?.child?.length">
              <FolderOpened />
            </el-icon>
            <el-icon v-else>
              <Document />
            </el-icon>
            {{ scope.row.folderName }}
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column align="center" label="编辑" width="200">
          <template #default="scope">
            <el-button link type="primary" :icon="useRenderIcon(EditPen)" @click="HandEdit(scope.row)"> 修改 </el-button>
            <el-button link type="danger" :icon="useRenderIcon(Delete)" @click="HandDelete(scope.row)"> 删除 </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 修改 or  删除 -->
    <el-dialog v-model="Visible" :title="Visibletitle" :close-on-click-modal="false" width="30%"
      @close="CloseData(refform)">
      <el-form ref="refform" label-width="120" :model="form" :rules="rules">
        <el-form-item label="父级层级" prop="parent">
          <el-tree-select v-model="form.parent" :data="dataList" :props="props" check-strictly
            :render-after-expand="false" class="!w-[80%]" :disabled="form.dataprocessFolderId != ''" />
        </el-form-item>
        <el-form-item label="层级名称" prop="folderName">
          <el-input v-model="form.folderName" class="!w-[80%]" />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="AddData(refform)">保存</el-button>
          <el-button @click="CloseData(refform)">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
const props = {
  label: 'folderName',
  value: "id",
  children: 'child',
}
import { PureTableBar } from "@/components/RePureTableBar";
import Opened from "@iconify-icons/ep/folder-opened";
import Folder from "@iconify-icons/ep/folder";
// import Document from "@iconify-icons/ep/document";
// import EditPen from "@iconify-icons/ep/edit-pen";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Delete from "@iconify-icons/ep/delete";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import {
  FolderOpened,
  Document,
  EditPen,
} from "@element-plus/icons-vue";
import { usehooks } from "./hooks";
const {
  form,
  rules,
  refform,
  Visible,
  loading,
  dataList,
  Visibletitle,
  AddData,
  CloseData,
  HandEdit,
  HandDelete
} = usehooks()
</script>

<style lang="scss" scoped>
.main {
  height: 100%;
  background-color: white;
  padding: 10px;
  overflow: hidden;
}

.main_btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 20px;
}

.main_table {
  height: calc(100% - 60px);
  overflow: auto;
  width: 100%;
}

:deep(.el-table__placeholder) {
  display: none;
}

:deep(.el-table__row:last-child) {
  display: none;
}
</style>
